<?php
header("Content-type: text/html; charset=utf-8");

define("ACCESS_TOKEN", 'b4vGW7FRIrYu1r1T3Cy07MUbmULhpGCyPplmSC9hqJZvNcjIdXOUQiDJ2fwiIsTFVEx0tVE7y3Pzb01KN_B3FA');

//创建菜单
function createMenu($data){
 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL, "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".ACCESS_TOKEN);
 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
 curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
 curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
 curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 $tmpInfo = curl_exec($ch);
 if (curl_errno($ch)) {
  return curl_error($ch);
 }
 curl_close($ch);
 return $tmpInfo;
}

$data = ' {
     "button":[
     
      {
           "name":"时讯",
           "sub_button":[
            {
               "type":"click",
               "name":"即时新闻",
               "key":"jsxw"
            },
            {
               "type":"click",
               "name":"财经早餐",
               "key":"cjzc"
            },
			{
               "type":"click",
               "name":"焦点话题",
               "key":"jdht"
            },
			{
               "type":"view",
               "name":"财经日历",
               "url":"http://stock1.sina.cn/dpool/stockv2/universal_calendar.php?vt=4"
            }]
       },
	   {
           "name":"说市",
           "sub_button":[
            {
               "type":"click",
               "name":"今日看盘",
               "key":"jrkp"
            },
            {
               "type":"view",
               "name":"行情刷新",
               "url":"http://XX/index.php/market/index"
            },
			{
               "type":"click",
               "name":"交易策略",
               "key":"jycl"
            },
			{
               "type":"click",
               "name":"投资天地",
               "key":"tztd"
            },
			{
               "type":"click",
               "name":"投资文库",
               "key":"tzwk"
            }]
       },
	   {
           "name":"北鼎在线",
           "sub_button":[
            {
               "type":"view",
               "name":"关于我们",
               "url":"http://www.index.php/article/index/id/114"
            },
            {
               "type":"view",
               "name":"最新活动",
               "url":"http://www.index.php/article/index/id/115"
            },
			{
               "type":"view",
               "name":"参与爆料",
               "url":"http://www.index.php/message"
            }
			]
       }
	   
	   
	   
	   
	   ]
 }';


echo createMenu($data);//创建菜单
?>